﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;
using YAPL.Language.SourceParser;
using YAPL.Language.Ast;
using YAPL.Language.SourceParser.XML;

namespace YAPL.Test.YAPL.Language.Parser.XML.NodeParsers {
	public class XmlConstantParserTest : XmlNodeParserTest {

		[Fact]
		public void ConstantShouldHaveValueAttribute() {
			var constantNode = new XElement(XmlNames.ConstantExpression);
			Assert.Throws<ArgumentNullException>(() => _parser.ParseNode(constantNode));
		}

		[Fact]
		public void ConstantStringLiteralShouldBeParsedCorrectly() {
			var constantNode = new XElement(XmlNames.ConstantExpression,
				new XAttribute(XmlNames.ConstantValueAttribute, "'literal'"));
			var expr = _parser.ParseNode(constantNode);
			Assert.IsType(typeof(ConstantExpression), expr);
			var constant = (ConstantExpression) expr;
			Assert.IsType(typeof(string),constant.Value);
			Assert.Equal("literal", constant.Value);
		}
	}
}